package com.hejiu45.hejiu45_api_test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hejiu45.hejiu45_api_test.entity.Users;
import com.hejiu45.hejiu45_api_test.mapper.UsersMapper;
import com.hejiu45.hejiu45_api_test.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
//@Transactional
public class UsersImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {
    @Autowired
    UsersMapper usersMapper;

    @Override
    public Boolean modify(Users users) {
        return usersMapper.updateById(users) > 0;
    }

    @Override
    public IPage<Users> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage, pageSize);
        return usersMapper.selectPage(page, null);
    }

    @Override
    public Users login(Users users) {
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.eq("uname", users.getUname())
                .eq("upasswd", users.getUpasswd());
        return usersMapper.selectOne(wrapper);
    }

    @Override
    public List<Users> getUsersLike(String userslike) {
        QueryWrapper<Users> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("uname", userslike);
        return usersMapper.selectList(queryWrapper);
    }
}
